package com.just.springbootbatch.controller;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    @Autowired
    JobLauncher jobLauncher;
    @Autowired
    @Qualifier("triggerJob")
    Job importJob;
    public JobParameters jobParameters;
    @RequestMapping("/imp")
    public String imp(String fileName){
        String path=fileName+".csv";
        jobParameters=new JobParametersBuilder()
                .addLong("time",System.currentTimeMillis())
                .addString("input.file.name",path)
                .toJobParameters();
        try {
            jobLauncher.run(importJob,jobParameters);
        } catch (Exception e) {
            return "oh ,no,出现异常了:"+e.getMessage();
        }
        return "ok";
    }
}
